//
//  HSSettingViewController.m
//  hsdyOrderSystem
//
//  Created by XunFengKJ on 2017/11/9.
//  Copyright © 2017年 赖国锋. All rights reserved.
//

#import "HSSettingViewController.h"
#import "XFForgetPassWordViewController.h"
#import "LoginViewController.h"

@interface HSSettingViewController ()
@property (weak, nonatomic) IBOutlet UILabel *versionL;//版本信息

@end

@implementation HSSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"设置";
    self.view.backgroundColor = LCOLOROFBACK;
    //当前版本号
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[versonString];
    self.versionL.text = [NSString stringWithFormat:@"v%@",currentVersion];
}

//修改密码
- (IBAction)changePassWordBtnClick:(id)sender {
    XFForgetPassWordViewController *forgetP = [XFForgetPassWordViewController new];
    forgetP.isFromLoginVC = NO;
    [self.navigationController pushViewController:forgetP animated:YES];
}

//退出登录
- (IBAction)quitLoginBtnClick:(id)sender{
    WEAKSELF
    [UIAlertController alertControllerShowInController:self Title:@"是否退出登录？" message:nil checkBlock:^{
        NSSet *tagSet = [NSSet setWithObject:@""];
        [JPUSHService setTags:tagSet alias:@"" fetchCompletionHandle:^(int iResCode, NSSet *iTags, NSString *iAlias) {
            
        }];
        [weakSelf deleteArchiveFile];
        [BookShareUserInforDefault clearUserInfoNil];
        //跳转到登录界面
        LoginViewController *loginVC = [[LoginViewController alloc] init];
        [weakSelf.navigationController pushViewController:loginVC animated:YES];
    }];
}

//删除归档文件
-(void)deleteArchiveFile{
    //获取路径和保存文件
    NSString *avartData = [NSString userDataPathWithPath:archiveAvarterImage];
    NSString *shoptimeData = [NSString userDataPathWithPath:archiveShopTimeData];
    NSString *shopNameData = [NSString userDataPathWithPath:archiveShopNameData];
    NSString *phoneData = [NSString userDataPathWithPath:archiveShopPhoneData];
    NSString *shopAddressData = [NSString userDataPathWithPath:archiveShopAddressData];
    NSString *shopintoData = [NSString userDataPathWithPath:archiveShopintroData];
    //删除归档文件
    [self deleteArchiverWithFileName:avartData];
    [self deleteArchiverWithFileName:shoptimeData];
    [self deleteArchiverWithFileName:shopNameData];
    [self deleteArchiverWithFileName:phoneData];
    [self deleteArchiverWithFileName:shopAddressData];
    [self deleteArchiverWithFileName:shopintoData];
}

/**
 *  删除归档文件
 */
-(void) deleteArchiverWithFileName:(NSString *)fileName{
    
    NSFileManager *defaultManager = [NSFileManager defaultManager];
    if ([defaultManager isDeletableFileAtPath:fileName]) {
        [defaultManager removeItemAtPath:fileName error:nil];
    }
}

@end
